<template>
  <div ref="container" id="dispatchReportPage">
    <el-container style="width: 80%; margin: 0 auto">
      <el-header class="header-bg header-line-height">
        <div v-bind:class="{ half: evaluated }">
          <h1 class="header-title">{{ form.textName }}</h1>
        </div>
        <div style="width: 50%; height: 100%; padding-top: 10%" v-if="evaluated">
          <div style="text-align: center">
            <h5>{{ columnName + ':' }}</h5>
            <h2>{{ evaluatedName }}</h2>
          </div>
          <div style="text-align: center">
            <h5>{{ columnName + '得分:' }}</h5>
            <h2 v-if="dataList.length > 0">{{ dataList[0].average }}</h2>
            <h2 v-else>0</h2>
          </div>
        </div>
      </el-header>
      <el-main>
        <el-select v-model="evaluated" @change="handleEvaluatedSelect" filterable>
          <el-option
            v-for="e in evaluatedList"
            :key="e.evaluated"
            :value="e.evaluated"
            :label="e.evaluatedName"
          ></el-option>
        </el-select>
        <h3 class="sub-title">素质项介绍</h3>
      </el-main>
    </el-container>
  </div>
</template>

<script>
import { Loading } from 'element-ui'
import { getRequest } from '@/api/baseRequest'
import { SET_EVALUATED_LIST } from '@/store/mutation-types'

export default {
  name: 'Report360',
  data() {
    return {
      dataList: [],
      type: '',
      reportTitle: '测评报告',
      formKey: '',
      evaluated: '',
      form: {},
      detailList: [],
      textDataList: [],
      isAll: 0,
      reportTypeList: [],
      evaluatedList: [],
      evaluatedName: '',
      showPrint: true
    }
  },
  filters: {
    numFilter(value) {
      // 截取当前数据到小数点后两位
      return parseFloat(value).toFixed(2)
    },
    isHalf() {
      return (this.evaluated.length = 0)
    }
  },
  computed: {
    columnName() {
      if (this.type == 5) {
        return '被评价部门'
      } else if (this.type == 6) {
        return '被评价人'
      } else {
        return '名称'
      }
    }
  },
  created() {
    this.type = this.$route.query.type
    this.formKey = this.$route.query.key
    this.evaluated = this.$route.query.evaluated
    this.isAll = this.$route.query.isAll || 0
    this.getTextData()
    this.getData()
    this.getEvaluatedList()
    this.$forceUpdate()
  },
  methods: {
    handleEvaluatedSelect(e) {
      this.$router.push({
        path: '/project/form/statistics',
        query: {
          key: this.formKey,
          type: this.type,
          evaluated: e,
          activeTab: 'report',
          isAll: this.columnName + '测评报告'
        }
      })
    },
    getData() {
      if (!this.evaluated) {
        return
      }
      let loadingInstance = Loading.service({ text: '正在生成报告' })
      getRequest('/report/getReport', { formKey: this.formKey, evaluated: this.evaluated })
        .then((res) => {
          if (res.code == 200) {
            this.dataList = res.data.evaluatedScoreDTOList
            if (this.dataList.length > 0) {
              this.evaluatedName = this.dataList[0].evaluatedName
            }
            this.form = res.data.userFormEntity
            this.detailList = res.data.formItemScoreDTOList
            console.log(this.form)
          }
        })
        .finally((res) => {
          loadingInstance.close()
        })
    },
    getTextData() {
      if (!this.evaluated) {
        return
      }
      getRequest('/report/getItemText', { formKey: this.formKey, evaluated: this.evaluated }).then((res) => {
        if (res.code == 200) {
          this.textDataList = res.data
        }
      })
    },
    getEvaluatedList() {
      const _this = this
      getRequest('/form/relationship/listDistinct', { formKey: this.formKey }).then((res) => {
        if (res.code === 200) {
          this.evaluatedList = res.data
          for (let e of this.evaluatedList) {
            if (e.evaluated == this.evaluated) {
              this.evaluated = e.evaluatedName
              this.evaluatedName = e.evaluatedName
            }
          }
          _this.$store.commit(SET_EVALUATED_LIST, res.data)
        }
      })
    }
  }
}
</script>

<style scoped>
.header-bg {
  background-image: url('~@/assets/images/bg-baogao@2x.png');
  background-repeat: no-repeat;
  background-size: 100% 100%;
}

.header-line-height {
  height: 400px !important;
  display: flex;
}

.header-title {
  text-align: center;
  margin: unset;
  color: white;
  /*line-height: 300px;*/
  font-size: 40px;
  margin-top: 30%;
}

.table-header {
  background: grey;
  font-size: 20px;
  font-weight: bolder;
}

.sub-title {
  border-left: 6px solid black;
  padding-left: 10px;
  font-weight: bold;
}

.half {
  /*float: left;*/
  width: 50%;
}

.red {
  color: #ff6161;
}

.green {
  color: #39b895;
}

.row-font {
  font-size: 40px;
}
</style>
